package task

import (
	baseLog "gitee.com/zaiqiang231/go-base-app/base_app/log"
	"github.com/robfig/cron/v3"
	"sync"
)

type TimedTaskManager struct {
}

var timedTaskManagerInstance *TimedTaskManager
var onceTimedTaskManager sync.Once

func GetTimedTaskManager() *TimedTaskManager {
	onceTimedTaskManager.Do(func() {
		timedTaskManagerInstance = new(TimedTaskManager)
	})
	return timedTaskManagerInstance
}

func (receiver TimedTaskManager) Start() {
	c := cron.New(cron.WithSeconds())
	c.AddFunc("*/30 * * * * *", func() { //0 * * * * *  //@every 1h30m30s
		baseLog.Infof("TimedTaskManager UidGen start")
		UidGen()
		baseLog.Infof("TimedTaskManager UidGen end")
	})
	baseLog.Infof("TimedTaskManager Start")
	c.Start()
}
